package com.hp.service;

import com.hp.bean.Customercoupon;
import com.hp.mapper.CustomerCouponMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class CustomerCouponServiceImp implements CustomerCouponService {
    @Resource
    private CustomerCouponMapper mapper;
    @Override
    @Transactional
    public int add(Integer id, String customerIds) {
        int k=0;
        String[] customerId=customerIds.split(",");
        for (int i=0;i<customerId.length;i++) {
            Integer cid=Integer.valueOf(customerId[i]);
            Customercoupon cc = new Customercoupon();
            cc.setCouponid(id);
            cc.setCustomerid(cid);
            cc.setAddtime(new Date());
            k+=mapper.insertCustomerCoupon(cc);

        }
        return k;
    }

    @Override
    public Customercoupon selectCustomerCouponById(Integer id) {
        return mapper.selectCustomerCouponById(id);
    }

    @Override
    public List<Customercoupon> selectCustomerCouponList(Customercoupon customercoupon) {
        return mapper.selectCustomerCouponList(customercoupon);
    }

    @Override
    public int insertCustomerCoupon(Customercoupon customercoupon) {
        return mapper.insertCustomerCoupon(customercoupon);
    }

    @Override
    public int updateCustomerCoupon(Customercoupon customercoupon) {
        return mapper.updateCustomerCoupon(customercoupon);
    }

    @Override
    public int deleteCustomerCouponByIds(String ids) {
        return mapper.deleteCustomerCouponByIds(ids);
    }

    @Override
    public int deleteCustomerCouponById(Integer id) {
        return mapper.deleteCustomerCouponById(id);
    }




}
